/*
 * @Author: 李石
 * @Date: 2024-04-28 18:13:35
 * @LastEditors: lishi
 * @LastEditTime: 2024-05-07 09:14:42
 * @Description: 
 * Copyright (c) 2024 by ${lishi0105@163.com}, All Rights Reserved. 
 */
#ifndef _CRYPT_UTIL_H_
#define _CRYPT_UTIL_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

#ifndef __FILENAME__
#define __FILENAME__                                                         \
    (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \
                                      : __FILE__)
#endif

#ifndef DBGI
#define DBGI(format...)                                       \
    do {                                                      \
        printf("\033[0;32m[%s:%d] ", __FILENAME__, __LINE__); \
        printf(format);                                       \
        printf("\033[0;39m");                                 \
    } while (0)
#endif

#ifndef DBGE
#define DBGE(format...)                                       \
    do {                                                      \
        printf("\033[0;31m[%s:%d] ", __FILENAME__, __LINE__); \
        printf(format);                                       \
        printf("\033[0;39m");                                 \
    } while (0)
#endif

int aes_encrypt(const unsigned char *plaintext, int plaintext_len,
                unsigned char *ciphertext, const unsigned char *key_,
                const unsigned char *iv_);

int aes_decrypt(const unsigned char *ciphertext, int ciphertext_len,
                unsigned char *plaintext, const unsigned char *key_,
                const unsigned char *iv_);

char *base64_encode(const unsigned char *input, int length);

unsigned char *base64_decode(const char *input, int *length);

int encrypt_base64(const void *plaintext, int plaintext_len, char *ciphertext,
                   int ciphertext_len);

int decrypt_base64(const char *ciphertext, int ciphertext_len, void *plaintext,
                   int plaintext_len);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif

#endif  // _CRYPT_UTIL_H_